home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / pas_0593.zip / STENCODE.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  2KB  |  58 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 274 of 314
  3. From : Keith Tysinger                      1:3648/2.0           11 May 93  19:18
  4. To   : Rob Perelman
  5. Subj : String-encoding
  6. ────────────────────────────────────────────────────────────────────────────────
  7. You can make an encoder that will scramble a string(s) that even YOU, the
  8. programmer couldn't unscramble without a password. They are many different ways
  9. to scramble a string; just be creative! One way is to swap every character with
  10. another character ( ex. swap every letter 'A' with the number '1') , a better
  11. way would use a password to scramble it. Here is a simple procedure that
  12. requires the password, the string to be scrammbled, and returns the scrambled
  13. string. The password should not exceed 20 characters in length.
  14. Forget about the messy code; I blame my word processor:}
  15.  
  16. procedure encode(password,instring:string;var outstring:string);
  17. var len,pcounter,scounter:byte;
  18.  
  19.      begin
  20.         len:=length(password) div 2;
  21.         scounter:=1;pcounter:=1;
  22.          repeat
  23.  
  24. outstring:=outstring+chr(ord(password[pcounter])+ord(instring[scounter])+len);
  25.            inc(scounter);inc(pcounter);
  26.            if pcounter>length(password) then pcounter:=1;
  27.            until scounter>length(instring);
  28.            end;
  29.  
  30. procedure decode(password,instring:string;var outstring:string);
  31. var len,pcounter,scounter:byte;
  32.  
  33.      begin
  34.         len:=length(password) div 2;
  35.  
  36.         scounter:=1;pcounter:=1;
  37.          repeat
  38.            outstring:=outstring+chr(ord(instring[scounter])-
  39. ord(password[pcounter]))-len);
  40.            inc(scounter);inc(pcounter);
  41.            if pcounter>length(password) then pcounter:=1;
  42.            until scounter>length(instring);
  43.            end;
  44.  
  45.  
  46.  
  47.  
  48. var password,original,scrambled,descrambled:string;
  49. begin
  50. original:='Encode This!';
  51. password:='Keith Tysinger';
  52. encode (password,original,scrambled);
  53. writeln('orig = ',original);
  54. writeln('scrm = ',scrambled);
  55. decode(password,scrambled,descrambled);
  56. writeln('dcod = ',descrambled);
  57. readln;
  58. end.